<?php

/**
 * This is the model class for table "{{alternativa}}".
 *
 * The followings are the available columns in table '{{alternativa}}':
 * @property integer $id_alternativa
 * @property integer $id_questao
 * @property string $texto
 * @property double $fator_multiplicativo
 *
 * The followings are the available model relations:
 * @property Questao $idQuestao
 * @property Resposta[] $respostas
 */
class Alternativa extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Alternativa the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{alternativa}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_questao, texto, fator_multiplicativo', 'required'),
			array('id_questao', 'numerical', 'integerOnly'=>true),
			array('fator_multiplicativo', 'numerical'),
			array('texto', 'length', 'max'=>250),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_alternativa, id_questao, texto, fator_multiplicativo', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'questoes' => array(self::BELONGS_TO, 'Questao', 'id_questao'),
			'respostas' => array(self::HAS_MANY, 'Resposta', 'id_alternativa'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_alternativa' => 'Id Alternativa',
			'id_questao' => 'Id Questao',
			'texto' => 'Texto',
			'fator_multiplicativo' => 'Fator Multiplicativo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_alternativa',$this->id_alternativa);
		$criteria->compare('id_questao',$this->id_questao);
		$criteria->compare('texto',$this->texto,true);
		$criteria->compare('fator_multiplicativo',$this->fator_multiplicativo);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}